<template>
    <div class="app-container">
        <el-card shadow="never">
        <!-- <p style="color:#fd2f2f;">请选择美国时间，对应时间：{{ us_time | parseTime('y-m-d h:i:s 星期a') }}</p> -->
        <!-- <el-calendar :range="['2023-05-01', '2025-05-01']">
            <template
                slot="dateCell"
                slot-scope="{date, data}">
                <p :class="data.isSelected ? 'is-selected' : ''">
                {{ data.day.split('-').slice(2).join('-') }} {{ data.isSelected ? '✔️' : ''}}
                </p>
            </template>
        </el-calendar> -->

            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="显示所有平台" prop="delivery">
                            <el-switch v-model="queryParams.delivery.value"></el-switch>
                        </el-form-item>
                    </el-col> -->
                    
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="日期:" prop="create_time.value">
                            <el-date-picker
                                v-model="queryParams.create_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="平台:" prop="adv_id.value">
                            <SelectPage v-model="queryParams.adv_id.value" :url="'/admin/advplatform/selectPage'" show_field="title" placeholder="请选择平台" query_field="title" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="域名:" prop="site_id.value">
                            <SelectPage v-model="queryParams.site_id.value" :url="'/admin/site/selectPage'" show_field="site_name" placeholder="请选择站点" query_field="site_name" :multiple="false" />
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col> -->
                </el-row>
            </el-form>
            
            
            <el-table
                :data="tableData"
                style="width: 100%"
                row-key="ids"
                border
                lazy
                :load="load"
                :row-class-name="tableRowClassName"
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                    <el-table-column
                        prop="site_name"
                        label="域名">
                    </el-table-column>
                    <el-table-column
                        prop="date_start"
                        label="日期">
                    </el-table-column>
                    <el-table-column
                        prop="spend"
                        label="总花费"
                        width="">
                    </el-table-column>
                    <el-table-column
                        prop="account_id"
                        :show-overflow-tooltip="true"
                        label="账户组">
                    </el-table-column>
                    <el-table-column
                        prop="adv_name"
                        label="平台"
                        width="150">
                    </el-table-column>
                    
            </el-table>
            <!-- 列表 -->
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
        <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            fileList: [],
            us_time: 0,
            value: new Date(),
            // table结构
            columns: [
                // {
                //     visible: true,
                //     label: 'id',
                //     prop: 'id',
                // },
                {
                    visible: true,
                    label: '花费',
                    prop: 'cost',
                },
                {
                    visible: true,
                    label: '平台',
                    prop: 'adv_name',
                },
                {
                    visible: true,
                    label: '账号',
                    prop: 'site_title',
                },
                {
                    visible: true,
                    label: 'cpc',
                    prop: 'cpc',
                },
                {
                    visible: true,
                    label: 'click',
                    prop: 'click',
                },
                {
                    visible: true,
                    label: '添加人',
                    prop: 'admin_title',
                },
                {
                    visible: true,
                    label: '消耗时间(美国日期)',
                    prop: 'create_time',
                },
                // {
                //     visible: true,
                //     label: '更新时间',
                //     prop: 'update_time',
                // },

            ],
            // 接口地址
            api: {
                index: `/admin/advertisingapi/index`,
                find: `/admin/advertisingapi/find`,
                add: `/admin/advertisingapi/add`,
                edit: `/admin/advertisingapi/edit`,
                delete: `/admin/advertisingapi/delete`,
                export: `/admin/advertisingapi/export`,
                upload: `https://api.fan-zhou.com/admin/advertisingapi/uploads`,
                status: `/admin/advertisingapi/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                create_time: { value: [], op: 'range' },
                admin_id: { value: [], op: '=' },
                site_id: { value:undefined, op: '='},
                adv_id: { value:undefined, op: '='},
                delivery: { value:false, op: '='},
            },

        }
    },
    created () {
        this.initIndex()
        this.now()
    },
    watch: {
        
    },
    methods: {
        tableRowClassName({row, rowIndex}) {
            if(row.hasChildren == true){
                return 'success-row';
            }else{
                return 'success-row2';
            }
        },
        load(tree, treeNode, resolve) {
            this.request
                .post('/admin/advertisingapi/get_adv_id', { id:tree.id,date_start:tree.date_start})
                .then(response => {
                    if(response.code == 1){
                        resolve(response.data)
                    }
                })
                .finally(() => {
                })
        },
        day_change() {
            
            console.log('test',this.value);
            console.log('data.isSelected',this.data.isSelected);
        },
        now() {
            this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            setInterval(() => {
                this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            }, 1000)
        },
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        
        submitUpload() {
            this.$refs.upload.submit();
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        
        // 上传成功回调
        handleUploadSuccess(res) {
            console.log('tesrest',res);
            if (res.code == 1) {
                this.$message.success('上传成功');
                this.initIndex();
            } else {
                this.$message({
                    type: 'error',
                    message: '上传失败'+res.msg,
                })
            }
        },
        // 上传失败
        handleUploadError() {
            this.$message({
                type: 'error',
                message: '上传失败',
            })
        },
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
.is-selected {
    color: #1989FA;
}
.el-table .success-row {
    background: #F0F9EB;
}
.el-table .success-row2 {
    background: #FDF5E6;
}
</style>